//
//  GameDetailTableViewCell_VIPPrice.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/3.
//

#import "GameDetailTableViewCell_VIPPrice.h"

@interface GameDetailTableViewCell_VIPPrice ()

@property (weak, nonatomic) IBOutlet UILabel *cellText;
@property (weak, nonatomic) IBOutlet UIView *vipView;

@end

@implementation GameDetailTableViewCell_VIPPrice

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)initCellData:(GameDetailNewModel *)detailModel
{
    self.cellText.text = detailModel.gameVipDesc;
    
    NSArray <GameDetailVipType*>*vipArray = detailModel.gameVipTypes;
    [self.vipView removeAllSubviews];
    UIView *vipContentView = [[UIView alloc] init];
    vipContentView.layer.cornerRadius = 10;
    vipContentView.layer.masksToBounds = YES;
    vipContentView.layer.borderColor = UIColorHex(0xD3BBA2).CGColor;
    vipContentView.layer.borderWidth = 1;
    [self.vipView addSubview:vipContentView];
    [vipContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.vipView);
    }];
    for (NSInteger i = 0; i <= vipArray.count; i++) {
        
        UIView *vipView = [[UIView alloc] init];
        [vipContentView addSubview:vipView];
        UIView *vipView_left = [[UIView alloc] init];
        
        [vipView addSubview:vipView_left];
        UIView *vipView_right = [[UIView alloc] init];
        [vipView addSubview:vipView_right];
        UIView *vipView_centerline = [[UIView alloc] init];
        vipView_centerline.backgroundColor = UIColorHex(0xD3BBA2);
        [vipView_left addSubview:vipView_centerline];
        
        UILabel *leftLabel = [[UILabel alloc] init];
        leftLabel.textAlignment = NSTextAlignmentCenter;
        [vipView_left addSubview:leftLabel];
        UILabel *rightLabel = [[UILabel alloc] init];
        rightLabel.textAlignment = NSTextAlignmentCenter;
        [vipView_right addSubview:rightLabel];
        
        UIView *vipView_topline = nil;
        if (i == 0) {
            vipView_left.backgroundColor = UIColorHex(F5E2CE);
            vipView_right.backgroundColor = UIColorHex(F5E2CE);
            leftLabel.font = [UIFont boldSystemFontOfSize:16];
            leftLabel.textColor = UIColorHex(0x7A532B);
            leftLabel.text = @"VIP等级";
            rightLabel.font = [UIFont boldSystemFontOfSize:16];
            rightLabel.textColor = UIColorHex(0x7A532B);
            rightLabel.text = @"RMB";
        } else {
            GameDetailVipType *vipType = vipArray[i-1];
            vipView_left.backgroundColor = [UIColor whiteColor];
            vipView_right.backgroundColor = [UIColor whiteColor];
            leftLabel.font = [UIFont systemFontOfSize:14];
            leftLabel.textColor = kColor333333;
            leftLabel.text = vipType.vipDengji;
            rightLabel.font = [UIFont systemFontOfSize:14];
            rightLabel.textColor = kColor333333;
            rightLabel.text = [NSString stringWithFormat:@"%@元", vipType.vipRMB];
            
            vipView_topline = [[UIView alloc] init];
            vipView_topline.backgroundColor = UIColorHex(0xD3BBA2);
            [vipView addSubview:vipView_topline];
        }
        
        [vipView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(vipContentView);
            make.height.mas_equalTo(40);
            make.top.mas_equalTo(40 * i);
        }];
        [vipView_left mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.height.equalTo(vipView);
            make.right.equalTo(vipView.mas_centerX);
        }];
        [vipView_right mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.height.equalTo(vipView);
            make.left.equalTo(vipView.mas_centerX);
        }];
        
        [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(vipView_left);
        }];
        [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(vipView_right);
        }];
        [vipView_centerline mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.height.equalTo(vipView_left);
            make.width.mas_equalTo(1);
        }];
        if (vipView_topline) {
            [vipView_topline mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.equalTo(vipView);
                make.height.mas_equalTo(1);
            }];
        }
        
        if (i == vipArray.count) {
            [vipContentView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(vipView);
            }];
        }
    }
    
}

+(CGFloat)height:(GameDetailNewModel *)detailModel
{
    CGFloat textHeight = [detailModel.gameVipDesc boundingRectWithSize:CGSizeMake(SL_WINDOW_WIDTH - 28, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil].size.height+1;
    CGFloat vipViewHeight = 40*5-10;
    if (detailModel.isOpen_VIP) {
        vipViewHeight = 40*(detailModel.gameVipTypes.count+1);
    }
    
    return 5 + textHeight + 5 + vipViewHeight;
}

@end
